package com.ruoyi.bnt.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bnt.domain.BntSpecialcolumninfo;
import com.ruoyi.bnt.service.IBntSpecialcolumninfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专栏详情Controller
 * 
 * @author yyj
 * @date 2020-09-29
 */
@Controller
@RequestMapping("/bnt/specialcolumn/specialcolumninfo")
public class BntSpecialcolumninfoController extends BaseController
{
    private String prefix = "bnt/specialcolumn/specialcolumninfo";

    @Autowired
    private IBntSpecialcolumninfoService bntSpecialcolumninfoService;

    @RequiresPermissions("bnt:specialcolumninfo:view")
    @GetMapping()
    public String specialcolumninfo()
    {
        return prefix + "/specialcolumninfo";
    }

    /**
     * 查询专栏详情列表
     */
    @RequiresPermissions("bnt:specialcolumninfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BntSpecialcolumninfo bntSpecialcolumninfo)
    {
        startPage();
        List<BntSpecialcolumninfo> list = bntSpecialcolumninfoService.selectBntSpecialcolumninfoList(bntSpecialcolumninfo);
        return getDataTable(list);
    }

    /**
     * 导出专栏详情列表
     */
    @RequiresPermissions("bnt:specialcolumninfo:export")
    @Log(title = "专栏详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BntSpecialcolumninfo bntSpecialcolumninfo)
    {
        List<BntSpecialcolumninfo> list = bntSpecialcolumninfoService.selectBntSpecialcolumninfoList(bntSpecialcolumninfo);
        ExcelUtil<BntSpecialcolumninfo> util = new ExcelUtil<BntSpecialcolumninfo>(BntSpecialcolumninfo.class);
        return util.exportExcel(list, "specialcolumninfo");
    }

    /**
     * 新增专栏详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/add/{parentId}")
    public String add(@PathVariable("parentId") String parentId, ModelMap mmap)
    {
        mmap.put("parentId", parentId);
        return prefix + "/add";
    }

    /**
     * 新增保存专栏详情
     */
    @RequiresPermissions("bnt:specialcolumninfo:add")
    @Log(title = "专栏详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BntSpecialcolumninfo bntSpecialcolumninfo)
    {
        if(bntSpecialcolumninfo.getId() == null || bntSpecialcolumninfo.getId().isEmpty())
            bntSpecialcolumninfo.setId(UUID.randomUUID().toString());
        return toAjax(bntSpecialcolumninfoService.insertBntSpecialcolumninfo(bntSpecialcolumninfo));
    }

    /**
     * 修改专栏详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BntSpecialcolumninfo bntSpecialcolumninfo = bntSpecialcolumninfoService.selectBntSpecialcolumninfoById(id);
        mmap.put("bntSpecialcolumninfo", bntSpecialcolumninfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存专栏详情
     */
    @RequiresPermissions("bnt:specialcolumninfo:edit")
    @Log(title = "专栏详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BntSpecialcolumninfo bntSpecialcolumninfo)
    {
        return toAjax(bntSpecialcolumninfoService.updateBntSpecialcolumninfo(bntSpecialcolumninfo));
    }

    /**
     * 删除专栏详情
     */
    @RequiresPermissions("bnt:specialcolumninfo:remove")
    @Log(title = "专栏详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bntSpecialcolumninfoService.deleteBntSpecialcolumninfoByIds(ids));
    }
}
